package cn.hbwe.controller;


import cn.hbwe.pojo.entity.Booking;
import cn.hbwe.pojo.entity.Schedule;
import cn.hbwe.pojo.vo.BookingVo;
import cn.hbwe.pojo.vo.DoctorVo;
import cn.hbwe.pojo.vo.ScheduleVo;
import cn.hbwe.pojo.vo.dScheduleVo;
import cn.hbwe.service.IScheduleService;
import cn.hbwe.util.PageVO;
import cn.hbwe.util.Result;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 7组
 * @since 2023-10-18
 */
@RestController
@RequestMapping("/schedule")
@Api(tags = "排班类接口")
@CrossOrigin
public class ScheduleController {
    @Autowired
    private IScheduleService scheduleService;

    /**
     * 为医生排班
     * @param schedule
     * @return
     */
    @ApiOperation("为医生排班")
    @PostMapping("/save")
    public Result<String> saveSchedule(@RequestBody Schedule schedule) {
        scheduleService.save(schedule);
        return Result.success("排班成功");
    }


    @ApiOperation("从排班表进行医生分页查询")
    @GetMapping("/{currentPage}/{pageSize}")
    public Result<PageVO<ScheduleVo>> getDoctorVo(@PathVariable Long currentPage, @PathVariable Long pageSize,Integer id) {
        PageVO<ScheduleVo> page = scheduleService.getScheduleVo(currentPage,pageSize,id);
        return Result.success(page);
    }


    /**
     * 根据时间查看排班信息
     * @param currentPage
     * @param pageSize
     * @param time
     * @return
     */
    @GetMapping("/time/{currentPage}/{pageSize}")
    @ApiOperation("根据时间查看排班信息")
    public Result<PageVO<ScheduleVo>> getByTime(@PathVariable Long currentPage, @PathVariable Long pageSize, String time) {
        System.out.println(time);
        PageVO<ScheduleVo> page = scheduleService.getByTime(currentPage,pageSize,time);
        return Result.success(page);
    }



    @PostMapping("/upallowance")
    @ApiOperation("修改余量")
    public Result<Schedule> modifyPatient(@RequestBody Schedule schedule) {
        scheduleService.updateById(schedule);
        return Result.success(schedule);

    }


    @ApiOperation("根据医生姓名和排版时间删除该记录")
    @DeleteMapping("/remove/{doctorName}/{time}")
    public Result<String> getByDoctor(@PathVariable String doctorName, @PathVariable String time){
        LambdaQueryWrapper<Schedule> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(Schedule::getDoctorName, doctorName).eq(Schedule::getScheduleDate, time);
        scheduleService.remove(lambdaQueryWrapper);
        return Result.success("删除排版记录成功");
    }

    @PutMapping("/modify")
    @ApiOperation("修改排班信息")
    public Result<String> modifySchedule(@RequestBody Schedule schedule) {
        scheduleService.updateById(schedule);
        return Result.success("医生信息修改成功");
    }

    //------------y------------------

    @GetMapping("/y/{currentPage}/{pageSize}")
    @ApiOperation("根据医生id查看排班信息")
    public Result<PageVO<dScheduleVo>> getByDoctorId(@PathVariable Long currentPage, @PathVariable Long pageSize, Integer doctorId) {
//        System.out.println("222222222222222222222222222222222");
        PageVO<dScheduleVo> page = scheduleService.getByDoctorId(currentPage,pageSize,doctorId);
        return Result.success(page);
    }
}
